package com.ocom.wxapi.controller;

import com.alibaba.fastjson.JSONObject;
import com.ocom.common.request.wx.ConsumeReportPageOnShowRequest;
import com.ocom.common.resp.Result;
import com.ocom.wxapi.client.PayConfigClientService;
import com.ocom.wxapi.client.XfRecordFeign;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@PreAuthorize("hasRole('ROLE_WX')")
@RequestMapping("/ConsumeReportPage")
@RestController
public class ConsumeReportPageController {

    @Autowired
    private XfRecordFeign xfRecordFeign;

    @Autowired
    PayConfigClientService payConfigClientService;

    @PostMapping("/onShow")
    public Result onShow(@Valid ConsumeReportPageOnShowRequest consumeReportPageOnShowRequest){
        JSONObject jsonObject=new JSONObject();
        jsonObject.put("comId",consumeReportPageOnShowRequest.getCompanyID());
        jsonObject.put("merchId",consumeReportPageOnShowRequest.getMachantID());
        jsonObject.put("pointed",-1);
        jsonObject.put("deviceNo",null);
        jsonObject.put("deptId",-1);
        jsonObject.put("reportType",1);
        jsonObject.put("groupbyLv",0);
        jsonObject.put("page",-1);
        jsonObject.put("size",-1);
        jsonObject.put("startTime",consumeReportPageOnShowRequest.getSummaryDate()+" 00:00:00");
        jsonObject.put("endTime",consumeReportPageOnShowRequest.getSummaryDate()+" 23:59:59");
        log.info("获取设备日报表参数 【{}】",jsonObject);
        Result getMealConsumeReports=payConfigClientService.getMealConsumeReports(consumeReportPageOnShowRequest.getCompanyID());
        if (getMealConsumeReports.getCode()!=200){
            return getMealConsumeReports;
        }
        jsonObject.put("mealNameInfos",getMealConsumeReports.getData());
        return xfRecordFeign.getConsumeReports(jsonObject);
    }
}
